﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace refTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Person p = new Person();
            p.Name = "rupeng";
            int i = 5;

            //Test(p, i);
            Test2(ref p,ref i);
            Console.WriteLine(p.Name);
            Console.WriteLine(i);

            int i1 = 5, i2 = 6;
            //不会交换
            Swap(i1, i2);
            Console.WriteLine("i1="+i1+",i2="+i2);
            //会交换
            Swap2(ref i1, ref i2);
            Console.WriteLine("i1=" + i1 + ",i2=" + i2);
            Console.ReadKey();
            
        }

        static void Test(Person p,int i)
        {
            //p.Name = "hahhaha";

             p = new Person();
            p.Name = "hahaha";
            i = 666;
        }

        static void Test2(ref Person p,ref int i)
        { 
            p = new Person();
            p.Name = "hahaha";
            i = 666;
        }

        static void Swap(int i1,int i2)
        {
            int temp = i1;
            i1 = i2;
            i2 = temp;
        }

        static void Swap2(ref int i1,ref int i2)
        {
            int temp = i1;
            i1 = i2;
            i2 = temp;
        }

        class Person
        {
            public string Name { get; set; }
        }
    }
}
